package com.example.microinvestcommon.util;

public class ThreadLocalUtil<T> {

    private static final ThreadLocal<Object> THREAD_LOCAL = new ThreadLocal<>();

    private ThreadLocalUtil() {
        throw new UnsupportedOperationException("Utility class");
    }

    @SuppressWarnings("unchecked")
    public static <T> T get() {
        T value = (T) THREAD_LOCAL.get();
        System.out.println("[ThreadLocalUtil.get] 当前线程: " + Thread.currentThread().getName() + "，值: " + value);
        return value;
    }

    public static void set(Object value) {
        System.out.println("[ThreadLocalUtil.set] 当前线程: " + Thread.currentThread().getName() + "，设置值: " + value);
        THREAD_LOCAL.set(value);
    }

    public static void remove() {
        System.out.println("[ThreadLocalUtil.remove] 当前线程: " + Thread.currentThread().getName() + "，清除 ThreadLocal");
        THREAD_LOCAL.remove();
    }

    // 👇 你要的 getThreadName 方法
    public static String getThreadName() {
        return Thread.currentThread().getName();
    }
}
